<?php 
	namespace Admin\Controller;
	use Think\Controller;
	//微博管理控制器
	class WeiboController extends CommonController{
		//原创微博视图
		public function index(){
			$where=array('isturn'=>0);
			$count=M('weibo')->where($where)->count();
			$Page = new \Think\Page($count,20); 
			$this->weibo=D('weiboView')->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('time desc')->select();
			$this->page=$Page->show();;			
			$this->display();
		}
		//转发微博
		public function turn(){
			$where=array('isturn'=>array('GT',0));
			$count=M('weibo')->where($where)->count();
			$Page = new \Think\Page($count,20); 
			$db=D('weiboView');
			//删除掉这个模型的picture表
			unset($db->viewFields['picture']);
			$this->turn=$db->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('time desc')->select();
			$this->page=$Page->show();;			
			$this->display();			
		}
		//删除微博
		public function delWeibo(){
			$wid=I('get.id');
			$uid=I('get.uid');
			if(M('weibo')->delete($wid)){
				M('userinfo')->where(array('id'=>$uid))->setDec('weibo');
				M('comment')->where(array('wid'=>$wid))->delete();
				M('keep')->where(array('wid'=>$wid))->delete();
				//删除微博图片
				$picture=M('picture')->field('mini,medm,max')->where(array('wid'=>$wid))->find();
				if($picture){
					 unlink('.'.substr($picture['mini'],6));
 			         unlink('.'.substr($picture['medm'],6));
			         unlink('.'.substr($picture['max'],6));
				}
				M('picture')->where(array('wid'=>$wid))->delete();
				M('atme')->where(array('wid'=>$wid))->delete();
				$this->success('删除成功',$_SERVER['HTTP_REFERER'],2);
			}else{
				$this->error('删除失败',$_SERVER['HTTP_REFERER'],2);
			}
		}
		//微博检索
		public function sechWeibo(){
			if (isset($_GET['sech'])) {
				$where=array('content'=>array('like','%'.$_GET['sech'].'%'));
				$db=D('WeiboView');
				//一些数据展示的话，最好用时间来进行排序
				$this->weibo=$db->where($where)->order('time desc')->select();
			}
			$this->display();
		}
		//评论列表
		public function comment(){
			$count=M('comment')->where($where)->count();
			$Page = new \Think\Page($count,20); 
			//返正展示多表数据就是用视图模型
			$this->comment=D('commentView')->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('time desc')->select();
			$this->page=$Page->show();
			$this->display(); 
		}
		//删除评论
		public function delComment(){
			$cid=I('get.id');
			$wid=I('get.wid');
			if(M('comment')->delete($cid)){
				M('weibo')->where(array('id'=>$wid))->setDec('comment');
				$this->success('删除成功',$_SERVER['HTTP_REFERER'],2);				
			}else{
				$this->success('删除失败',$_SERVER['HTTP_REFERER'],2);								
			}
		}
		//评论检索
		public function sechComment(){
			if (isset($_GET['sech'])) {
				$where=array('content'=>array('like','%'.$_GET['sech'].'%'));
				$db=D('CommentView');
				//一些数据展示的话，最好用时间来进行排序
				$this->comment=$db->where($where)->order('time desc')->select();
			}
			$this->display();			
		}
	}
 ?>		
